package cn.edu.nuc.creditSystem.service.credit.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.nuc.creditSystem.bean.Msg;
import cn.edu.nuc.creditSystem.bean.credit.Loanbid;
import cn.edu.nuc.creditSystem.bean.user.User;
import cn.edu.nuc.creditSystem.dao.BaseMapper;
import cn.edu.nuc.creditSystem.dao.credit.inf.LoanbidMapper;
import cn.edu.nuc.creditSystem.dao.user.inf.UserMapper;
import cn.edu.nuc.creditSystem.service.BaseImpl;
import cn.edu.nuc.creditSystem.service.credit.service.LoanbidService;
@Service
public class LoanbidImpl extends BaseImpl<Loanbid> implements LoanbidService{
	@Autowired
	private LoanbidMapper lm;
	@Autowired
	private UserMapper um;
	@Override
	public BaseMapper<Loanbid> getBaseDao() {
		return lm;
	}
	@Override
	public List<User> querySecurity(Double money) {
		return lm.querySecurity(money);
	}
	@Override
	public Msg toTransferLoanbid(User user,User user2,Integer loanid, String otherUsername) {
		if(!user.getPassword().equals(user2.getPassword())||!user.getPhone().equals(user2.getPhone())||!user.getEmail().equals(user2.getEmail())){
			return new Msg(Msg.error,"您的个人信息不正确，请您核对！");
		}else{
			User otherUser=um.getUserByUsername(otherUsername);
			Loanbid l=lm.get(loanid);
			if(l.getCrediter()!=user2.getId()){
				return new Msg(Msg.error,"系统出错，此贷款标的购入方不是您的！");
			}else{
				l.setCrediter(otherUser.getId());
				if(lm.update(l)>0){
					return new Msg(Msg.success,"债权转让操作成功");
				}
			}
		}
		return new Msg(Msg.error,"转让失败！");
	}
}
